package com.ruoyi.web.controller.snmp;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SnmpSensubjectdevice;
import com.ruoyi.system.service.ISnmpSensubjectdeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 传感器主题和设备关联数据Controller
 *
 * @author ruoyi
 * @date 2025-08-26
 */
@RestController
@RequestMapping("/snmp/sensubjectdevice")
public class SnmpSensubjectdeviceController extends BaseController
{
    @Autowired
    private ISnmpSensubjectdeviceService snmpSensubjectdeviceService;

    /**
     * 查询传感器主题和设备关联数据列表
     */
    @PreAuthorize("@ss.hasPermi('snmp:sensubjectdevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnmpSensubjectdevice snmpSensubjectdevice)
    {
        startPage();
        List<SnmpSensubjectdevice> list = snmpSensubjectdeviceService.selectSnmpSensubjectdeviceList(snmpSensubjectdevice);
        return getDataTable(list);
    }
    @GetMapping("/getlist/deviceId/{deviceId}")
    public AjaxResult getlist(@PathVariable("deviceId") String deviceId)
    {
        SnmpSensubjectdevice snmpSensubjectdevice=new  SnmpSensubjectdevice();
        snmpSensubjectdevice.setDeviceId(deviceId);
        List<SnmpSensubjectdevice> list = snmpSensubjectdeviceService.selectSnmpSensubjectdeviceList(snmpSensubjectdevice);
        return success(list);
    }
    /**
     * 导出传感器主题和设备关联数据列表
     */
    @PreAuthorize("@ss.hasPermi('snmp:sensubjectdevice:export')")
    @Log(title = "传感器主题和设备关联数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnmpSensubjectdevice snmpSensubjectdevice)
    {
        List<SnmpSensubjectdevice> list = snmpSensubjectdeviceService.selectSnmpSensubjectdeviceList(snmpSensubjectdevice);
        ExcelUtil<SnmpSensubjectdevice> util = new ExcelUtil<SnmpSensubjectdevice>(SnmpSensubjectdevice.class);
        util.exportExcel(response, list, "传感器主题和设备关联数据数据");
    }

    /**
     * 获取传感器主题和设备关联数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('snmp:sensubjectdevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(snmpSensubjectdeviceService.selectSnmpSensubjectdeviceById(id));
    }

    /**
     * 新增传感器主题和设备关联数据
     */
    @Log(title = "设备关联传感器主题数据", businessType = BusinessType.INSERT)
    @PostMapping("/addlist")
    public AjaxResult addlist(@RequestBody List<SnmpSensubjectdevice> sensubjectdeviceData) {
        int result = 0;
        if (sensubjectdeviceData.size() > 0 && sensubjectdeviceData.get(0).getDeviceId() != null
                && sensubjectdeviceData.get(0).getDeviceId().length() > 0) {
            snmpSensubjectdeviceService.deleteSnmpSensubjectdeviceByDevice(sensubjectdeviceData.get(0).getDeviceId());

            for (SnmpSensubjectdevice snmpSensubjectdevice : sensubjectdeviceData
            ) {
                result = result + snmpSensubjectdeviceService.insertSnmpSensubjectdevice(snmpSensubjectdevice);
            }
        }
        return toAjax(result);
    }

    @Log(title = "传感器主题和设备关联数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnmpSensubjectdevice snmpSensubjectdevice)
    {
        return toAjax(snmpSensubjectdeviceService.insertSnmpSensubjectdevice(snmpSensubjectdevice));
    }

    /**
     * 修改传感器主题和设备关联数据
     */
    @PreAuthorize("@ss.hasPermi('snmp:sensubjectdevice:edit')")
    @Log(title = "传感器主题和设备关联数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnmpSensubjectdevice snmpSensubjectdevice)
    {
        return toAjax(snmpSensubjectdeviceService.updateSnmpSensubjectdevice(snmpSensubjectdevice));
    }

    /**
     * 删除传感器主题和设备关联数据
     */
    @PreAuthorize("@ss.hasPermi('snmp:sensubjectdevice:remove')")
    @Log(title = "传感器主题和设备关联数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(snmpSensubjectdeviceService.deleteSnmpSensubjectdeviceByIds(ids));
    }
}
